package com.itboye.sunsun.person.ui;

import com.itboye.sunsun.R;
import com.itboye.sunsun.Application.App;
import com.itboye.sunsun.address.AddressSelectView;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

public class AddressFragment extends DialogFragment implements OnClickListener {

	private AddressSelectView addressSelect;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		View v = inflater.inflate(R.layout.fragment_address2, container, false);
		v.findViewById(R.id.btn_confirm).setOnClickListener(this);
		addressSelect = (AddressSelectView) v.findViewById(R.id.addressselect);
		return v;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setStyle(STYLE_NO_TITLE, R.style.AddressDialog);
	}

	@Override
	public void onStart() {
		super.onStart();
		final DisplayMetrics dm = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

		final WindowManager.LayoutParams layoutParams = getDialog().getWindow()
				.getAttributes();
		layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
		layoutParams.gravity = Gravity.BOTTOM;
		getDialog().getWindow().setAttributes(layoutParams);
	}

	@Override
	public void onClick(View arg0) {
		addressSelect.getResult();
		Toast.makeText(App.ctx, addressSelect.getResult(), 0).show();
		this.dismiss();

	}

}
